//
// Created by jsjxsy on 2022/8/18.
// = 只能作为成员函数
//
#include <iostream>
using namespace std;
class Point {
 public:
  Point(int x = 0, int y = 0) : x(x), y(y) {
    cout << "construct Point(x=" << x << ",y=" << y << ")" << endl;
  }
  Point &operator=(const Point &other);
  Point operator()(const Point &other);
  int operator[](int index);
  int x;
  int y;
};
Point &Point::operator=(const Point &other) {
  if (this != &other) {
    x = other.x;
    y = other.y;
  }
  return *this;
}
Point Point::operator()(const Point &other) {
  return Point(x + other.x, y + other.y);
}

int Point::operator[](int index) {
  if (index > 1) {
    throw std::invalid_argument("[] operation index out of range");
  }
  if (index == 0) {
    return x;
  } else {
    return y;
  }
}
int Point::operator->() {
  return 0;
}

int main() {
  Point p1(1, 1);
  Point p2(3, 5);
  Point p3;
  p3 = p2;
  cout << "p3(x=" << p3.x << ",y=" << p3.y << ")" << endl;
  p3 = p1;
  cout << "p3(x=" << p3.x << ",y=" << p3.y << ")" << endl;
  p3 = p3(p1);
  cout << "p3(x=" << p3.x << ",y=" << p3.y << ")" << endl;
  cout << "x=" << p3[0] << ",y=" << p3[1] << endl;
  return 0;
}
